import { defineConfig, loadEnv, ConfigEnv, UserConfig } from 'vite'
import { initVitePlugins } from './vite/plugins'
import { initProxy } from './vite/plugins/proxy'
import { wrapperEnv } from './vite/getEnv'
import { resolve } from 'path'
const pathSrc = resolve(__dirname, 'src')
// https://vitejs.dev/config/
export default defineConfig(({ mode, command }: ConfigEnv): UserConfig => {
  const root = process.cwd()
  const env = loadEnv(mode, root)
  const viteEnv = wrapperEnv(env)
  return {
    server: {
      host: '0.0.0.0',
      port: viteEnv.VITE_PORT,
      open: viteEnv.VITE_OPEN,
      proxy: initProxy(viteEnv.VITE_PROXY)
    },
    resolve: {
      alias: {
        '@': pathSrc
      }
    },
    plugins: initVitePlugins(viteEnv, command === 'build'),
    build: {
      outDir: 'D:/nginx-1.25/html',
      minify: 'esbuild',
      sourcemap: false
    },
    css: {
      // CSS 预处理器
      preprocessorOptions: {
        // 定义全局 SCSS 变量
        scss: {
          silenceDeprecations: ['legacy-js-api'],
          javascriptEnabled: true,
          additionalData: `@import "@/assets/styles/variables.scss";`
        }
      }
    },
    optimizeDeps: {
      include: [
        'vue',
        'vue-router',
        'pinia',
        'vue-i18n',
        'axios',
        '@vueuse/core',
        'element-plus/es/components/popover/style/css',
        'element-plus/es/components/tabs/style/css',
        'element-plus/es/components/button/style/css',
        'element-plus/es/components/tab-pane/style/css',
        'element-plus/es/components/rate/style/css',
        'element-plus/es/components/container/style/css',
        'element-plus/es/components/header/style/css',
        'element-plus/es/components/aside/style/css',
        'element-plus/es/components/scrollbar/style/css',
        'element-plus/es/components/drawer/style/css',
        'element-plus/es/components/divider/style/css',
        'element-plus/es/components/icon/style/css',
        'element-plus/es/components/footer/style/css',
        'element-plus/es/components/main/style/css',
        'element-plus/es/components/tooltip/style/css',
        'element-plus/es/components/switch/style/css',
        'element-plus/es/components/menu/style/css',
        'element-plus/es/components/color-picker/style/css',
        'element-plus/es/components/breadcrumb/style/css',
        'element-plus/es/components/breadcrumb-item/style/css',
        'element-plus/es/components/menu-item/style/css',
        'element-plus/es/components/sub-menu/style/css',
        'element-plus/es/components/dropdown/style/css',
        'element-plus/es/components/dropdown-item/style/css',
        'element-plus/es/components/message-box/style/css',
        'element-plus/es/components/dropdown-menu/style/css',
        'element-plus/es/components/form/style/css',
        'element-plus/es/components/image/style/css',
        'element-plus/es/components/form-item/style/css',
        'element-plus/es/components/input/style/css',
        'element-plus/es/components/table/style/css',
        'element-plus/es/components/table-column/style/css',
        'element-plus/es/components/date-picker/style/css',
        'element-plus/es/components/select/style/css',
        'element-plus/es/components/option/style/css',
        'element-plus/es/components/row/style/css',
        'element-plus/es/components/col/style/css',
        'element-plus/es/components/popconfirm/style/css',
        'element-plus/es/components/tag/style/css',
        'element-plus/es/components/radio/style/css',
        'element-plus/es/components/pagination/style/css',
        'element-plus/es/components/check-tag/style/css',
        'element-plus/es/components/space/style/css',
        'element-plus/es/locale/lang/en'
      ]
    }
  }
})
